import type { NumberKind } from "../types.js";
import type { CheckData } from "./CheckData.js";

export interface BaseResField {
    /** 字段名称 */
    name: string;
}

export interface EqualResField extends BaseResField {
    kind: "equal";
    data: ArrayLike<number>;
    value: string;
}

export interface NumberResField extends BaseResField {
    kind: NumberKind;
}

export interface CustomResField extends BaseResField {
    kind: "custom";
    /**
     * 自定义字段的描述
     */
    desc: string;
    /**
     * 判断字段是否符合规则
     * @param data 剩余数据
     * @returns 相同的数据长度，如果不相同返回-1
     */
    matcher: (data: CheckData) => string | null;
}

export interface StringResField extends BaseResField {
    kind: "string";
    length?: number | undefined;
}

export interface HexResField extends BaseResField {
    kind: "hex";
    length?: number | undefined;
}

export type ResField = EqualResField | CustomResField | NumberResField | StringResField | HexResField;

export interface ResponseOption {
    /** 接口名称 */
    name?: string | undefined;
    /** 接口描述 */
    description: string;
    /** 返回数据 */
    fields: ResField[];
}
